package com.jmes.web.filter;

import org.apache.ibatis.logging.LogFactory;
import org.apache.log4j.xml.DOMConfigurator;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * 编码拦截器
 * User: jinshunlong
 * Date: 13-4-13
 * Time: 下午9:39
 */
public class CharacterEncodingFilter implements Filter {
    private String encoding;


    public void setEncoding(String encoding) {
        this.encoding = encoding;
    }

    public void destroy() {
        // TODO Auto-generated method stub

    }

    public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest)req;

        if(encoding==null||encoding.trim().length()==0)
            request.setCharacterEncoding("UTF-8");
        else
            request.setCharacterEncoding(encoding);
        chain.doFilter(request, res);
    }

    public void init(FilterConfig config) throws ServletException {

    }

}
